package com.ssm.hj.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.hj.page.Page;
import com.ssm.hj.search.Search;
import com.ssm.hj.service.MouldService;
import com.ssm.hj.view.MouldView;
import com.ssm.mapper.MouldMapper;
import com.ssm.pojo.Mould;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class MouldServiceImpl implements MouldService {
    @Resource
    private MouldMapper mouldMapper;
    @Override
    public PageInfo<Mould> queryMouldAllService(Page<Search> page) throws Exception {
        PageHelper.startPage(page.getPageNum(),page.getPageSize());
        return new PageInfo<Mould>(this.mouldMapper.queryMouldAll(page.getSearchObj()));
    }

    @Override
    public int saveMouldService(MouldView mouldView){
        try {
            this.mouldMapper.saveMould(mouldView.getMould());
            System.out.println("-------------------"+mouldView.getMould().getId());
            this.mouldMapper.saveMouldFood(mouldView.getMould().getId(),mouldView.getFood());
            this.mouldMapper.saveMouldExercise(mouldView.getMould().getId(),mouldView.getExercise());
            return 1;
        }catch (Exception e){
            e.printStackTrace();
            return 0;
        }
    }
}
